from PIL import Image, ImageDraw
import random
import math

def draw_cat(draw, size):
    face_color = (255, 255, random.randint(180, 255))
    draw.ellipse((8, 12, size-8, size-8), fill=face_color, outline=(0,0,0), width=2)
    draw.polygon([(16,20), (8,8), (28,16)], fill=face_color, outline=(0,0,0))
    draw.polygon([(size-16,20), (size-8,8), (size-28,16)], fill=face_color, outline=(0,0,0))
    for ex in [size//2-10, size//2+10]:
        draw.ellipse((ex-3, size//2-2, ex+3, size//2+4), fill=(0,0,0))
    draw.ellipse((size//2-2, size//2+6, size//2+2, size//2+10), fill=(255,150,150), outline=(0,0,0))
    draw.arc((size//2-6, size//2+8, size//2, size//2+16), 0, 180, fill=(0,0,0), width=1)
    draw.arc((size//2, size//2+8, size//2+6, size//2+16), 0, 180, fill=(0,0,0), width=1)
    for dy in [0, 4]:
        draw.line((size//2-2, size//2+8+dy, size//2-12, size//2+8+dy), fill=(0,0,0), width=1)
        draw.line((size//2+2, size//2+8+dy, size//2+12, size//2+8+dy), fill=(0,0,0), width=1)

def draw_rabbit(draw, size):
    face_color = (255, 255, 255)
    draw.ellipse((10, 18, size-10, size-8), fill=face_color, outline=(0,0,0), width=2)
    draw.ellipse((size//2-18, 2, size//2-4, 28), fill=face_color, outline=(0,0,0), width=2)
    draw.ellipse((size//2+4, 2, size//2+18, 28), fill=face_color, outline=(0,0,0), width=2)
    for ex in [size//2-8, size//2+8]:
        draw.ellipse((ex-2, size//2+2, ex+2, size//2+6), fill=(0,0,0))
    draw.ellipse((size//2-2, size//2+10, size//2+2, size//2+14), fill=(255,150,150), outline=(0,0,0))
    draw.arc((size//2-6, size//2+12, size//2, size//2+18), 0, 180, fill=(0,0,0), width=1)
    draw.arc((size//2, size//2+12, size//2+6, size//2+18), 0, 180, fill=(0,0,0), width=1)

def draw_bear(draw, size):
    face_color = (220, 180, 120)
    draw.ellipse((10, 14, size-10, size-8), fill=face_color, outline=(0,0,0), width=2)
    draw.ellipse((6, 2, 22, 18), fill=face_color, outline=(0,0,0), width=2)
    draw.ellipse((size-22, 2, size-6, 18), fill=face_color, outline=(0,0,0), width=2)
    for ex in [size//2-8, size//2+8]:
        draw.ellipse((ex-2, size//2+2, ex+2, size//2+6), fill=(0,0,0))
    draw.ellipse((size//2-3, size//2+10, size//2+3, size//2+16), fill=(80,60,40), outline=(0,0,0))
    draw.arc((size//2-6, size//2+14, size//2, size//2+20), 0, 180, fill=(0,0,0), width=1)
    draw.arc((size//2, size//2+14, size//2+6, size//2+20), 0, 180, fill=(0,0,0), width=1)

def draw_dog(draw, size):
    face_color = (230, 200, 160)
    draw.ellipse((10, 16, size-10, size-8), fill=face_color, outline=(0,0,0), width=2)
    draw.ellipse((4, 8, 20, 28), fill=face_color, outline=(0,0,0), width=2)
    draw.ellipse((size-20, 8, size-4, 28), fill=face_color, outline=(0,0,0), width=2)
    for ex in [size//2-8, size//2+8]:
        draw.ellipse((ex-2, size//2+2, ex+2, size//2+6), fill=(0,0,0))
    draw.ellipse((size//2-2, size//2+10, size//2+2, size//2+14), fill=(80,60,40), outline=(0,0,0))
    draw.arc((size//2-6, size//2+14, size//2, size//2+20), 0, 180, fill=(0,0,0), width=1)
    draw.arc((size//2, size//2+14, size//2+6, size//2+20), 0, 180, fill=(0,0,0), width=1)

def draw_pig(draw, size):
    face_color = (255, 200, 200)
    draw.ellipse((10, 16, size-10, size-8), fill=face_color, outline=(0,0,0), width=2)
    draw.ellipse((6, 6, 22, 22), fill=face_color, outline=(0,0,0), width=2)
    draw.ellipse((size-22, 6, size-6, 22), fill=face_color, outline=(0,0,0), width=2)
    for ex in [size//2-8, size//2+8]:
        draw.ellipse((ex-2, size//2+2, ex+2, size//2+6), fill=(0,0,0))
    draw.ellipse((size//2-6, size//2+10, size//2+6, size//2+18), fill=(255,150,150), outline=(0,0,0))
    draw.ellipse((size//2-3, size//2+13, size//2-1, size//2+15), fill=(0,0,0))
    draw.ellipse((size//2+1, size//2+13, size//2+3, size//2+15), fill=(0,0,0))

def draw_chick(draw, size):
    face_color = (255, 255, 120)
    draw.ellipse((12, 16, size-12, size-8), fill=face_color, outline=(0,0,0), width=2)
    draw.polygon([(size//2-2, size//2+12), (size//2+2, size//2+12), (size//2, size//2+18)], fill=(255,180,0), outline=(0,0,0))
    for ex in [size//2-6, size//2+6]:
        draw.ellipse((ex-2, size//2+2, ex+2, size//2+6), fill=(0,0,0))
    draw.ellipse((size//2-4, 8, size//2, 14), fill=(255,80,80), outline=(0,0,0))
    draw.ellipse((size//2, 6, size//2+4, 14), fill=(255,80,80), outline=(0,0,0))

def draw_frog(draw, size):
    face_color = (180, 255, 180)
    draw.ellipse((10, 16, size-10, size-8), fill=face_color, outline=(0,0,0), width=2)
    for ex in [size//2-10, size//2+10]:
        draw.ellipse((ex-4, 6, ex+4, 14), fill=(255,255,255), outline=(0,0,0))
        draw.ellipse((ex-1, 10, ex+1, 12), fill=(0,0,0))
    draw.arc((size//2-8, size//2+10, size//2+8, size//2+18), 20, 160, fill=(0,0,0), width=2)

def draw_fox(draw, size):
    face_color = (255, 180, 80)
    draw.ellipse((10, 16, size-10, size-8), fill=face_color, outline=(0,0,0), width=2)
    draw.polygon([(14,18), (8,6), (28,18)], fill=face_color, outline=(0,0,0))
    draw.polygon([(size-14,18), (size-8,6), (size-28,18)], fill=face_color, outline=(0,0,0))
    for ex in [size//2-8, size//2+8]:
        draw.ellipse((ex-2, size//2+2, ex+2, size//2+6), fill=(0,0,0))
    draw.ellipse((size//2-2, size//2+10, size//2+2, size//2+14), fill=(0,0,0))

def draw_mouse(draw, size):
    face_color = (220, 220, 220)
    draw.ellipse((10, 16, size-10, size-8), fill=face_color, outline=(0,0,0), width=2)
    draw.ellipse((6, 6, 22, 22), fill=face_color, outline=(0,0,0), width=2)
    draw.ellipse((size-22, 6, size-6, 22), fill=face_color, outline=(0,0,0), width=2)
    for ex in [size//2-8, size//2+8]:
        draw.ellipse((ex-2, size//2+2, ex+2, size//2+6), fill=(0,0,0))
    draw.ellipse((size//2-2, size//2+12, size//2+2, size//2+16), fill=(255,150,150), outline=(0,0,0))
    for dy in [0, 4]:
        draw.line((size//2-2, size//2+14+dy, size//2-12, size//2+14+dy), fill=(0,0,0), width=1)
        draw.line((size//2+2, size//2+14+dy, size//2+12, size//2+14+dy), fill=(0,0,0), width=1)

def draw_lion(draw, size):
    face_color = (255, 220, 120)
    draw.ellipse((2, 8, size-2, size-2), fill=(255,180,60), outline=(0,0,0), width=2)
    draw.ellipse((10, 16, size-10, size-8), fill=face_color, outline=(0,0,0), width=2)
    for ex in [size//2-8, size//2+8]:
        draw.ellipse((ex-2, size//2+2, ex+2, size//2+6), fill=(0,0,0))
    draw.ellipse((size//2-2, size//2+10, size//2+2, size//2+14), fill=(80,60,40), outline=(0,0,0))
    draw.arc((size//2-6, size//2+14, size//2, size//2+20), 0, 180, fill=(0,0,0), width=1)
    draw.arc((size//2, size//2+14, size//2+6, size//2+20), 0, 180, fill=(0,0,0), width=1)

def create_animal_icon(filename='random_icon.ico'):
    """生成动漫简笔动物ico图标"""
    size = 64
    img = Image.new('RGBA', (size, size), (255,255,255,0))
    draw = ImageDraw.Draw(img)
    animals = [
        draw_cat, draw_rabbit, draw_bear, draw_dog, draw_pig,
        draw_chick, draw_frog, draw_fox, draw_mouse, draw_lion
    ]
    animal_func = random.choice(animals)
    animal_func(draw, size)
    img.save(filename, format='ICO', sizes=[(64,64), (48,48), (32,32), (16,16)])

if __name__ == '__main__':
    create_animal_icon('random_icon.ico')
    print("已生成动漫简笔动物icon：random_icon.ico")